package com.yangzihao;


import com.yangzihao.entity.NewsCategory;
import com.yangzihao.entity.NewsDetail;
import com.yangzihao.mapper.NewsDetailMapper;
import com.yangzihao.service.NewsCategoryService;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.Date;
import java.util.List;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(value = "classpath:applicationContext.xml")
public class demo1 {

    @Autowired
    private NewsCategoryService newsCategoryService;

    @Autowired
    private NewsDetailMapper newsDetailMapper;

    @Test
    public void run1(){
        NewsCategory newsCategory=new NewsCategory();
        newsCategory.setName("影视");
        newsCategoryService.insertNewsCat(newsCategory);
    }


    @Test
    public void run2(){
        NewsDetail newsDetail=new NewsDetail();
        newsDetail.setCategoryId(5);
        newsDetail.setTitle("我是女强人");
        newsDetail.setSummary("彪悍的人生不需要解释");
        newsDetail.setAuthor("胡一飞");
        newsDetail.setCreateDate(new Date());
        newsDetail.setUpdateDate(new Date());
        newsDetailMapper.insertNewsDet(newsDetail);
    }



    @Test
    public void run3(){

        NewsDetail newsDetail=new NewsDetail();
        newsDetail.setCategoryId(5);
        newsDetail.setTitle("他");
        List<NewsDetail> byCondition = newsDetailMapper.findByCondition(newsDetail);
        System.out.println(byCondition);
    }

    @Test
    public void run4(){
        NewsDetail detail = newsDetailMapper.findById(1);
        System.out.println(detail);
    }

    @Test
    public void run9(){
        NewsDetail title = newsDetailMapper.findByTitle("非常帅气的一个人");
        System.out.println(title);
    }

}
